Termination Analysis for Ooine Partial Evaluation of a Higher Order Functional Language

نویسندگان

  • Peter Holst Andersen
  • Carsten Kehler Holst
چکیده

Transition Semantics. The abstraction transition semantics, which collects abstract 1-step transitions and compositions of these, is given below. AbsTrans = Fnames Fnames 7! P(SizeDep ) CS : AnnExp! Fenv! AbsTrans CSfi [[Clo(fj ; he1; : : : ; eni)]] = Fk CSfi [[ek]] CSfi [[Clo(fj ; he1; : : : ; eni)]] = Fk CSfi [[ek]] t [hfi; fji 7! hS [[e1]] ; : : : ;S[[en]] ;?; : : :;?i] CSfi [[e (e1; : : : ; en)]] = CSfi [[e]] t Fj CSfi [[ej ]] t [hfi; fji 7! h 1; : : : ; m;S[[e1]] ; : : : ;S[[en]] i j Clo(fj ; h 1; : : : ; mi) 2 S[[e]] #SizeDep ; arity(fj) = n] CSfi [[e @ (e1; : : : ; en)]] = CSfi [[e]] t Fj CSfi [[ej ]] p = x :[fi 7! S [[ei]] j fi(: : :)(: : :) = ei 2 p] 1-atransp = Fi CSfi [[e]] p; where fi(: : :)(: : :) = e 2 p, and fi is reachable atransp = x T:( [hfi; fki 7! t2 ] t1 j [hfi; fji 7! t1]; [hfj; fki 7! t2] 2 T ] t 1-atransp) The non-trivial entries in the abstract semantics are those for application and the creation of closures. Notice how static closure creation match static application, and residual closure creation match residual application:A static closure creation gives rise to transitions at application time and not at creation time, whereas residual closure creation contribute at creation time but not when applied. During partial evaluation of a residual creation of a closure Clo(fj ; : : :), a transition to fj occurs, because the specializer evaluates the body of fj (yielding a reduced expression). To model this behavior we collect an abstract transition from the calling function to fj in which the lambda-bound variables are described by ? (because they are dynamic). Static application generates a transition for each closure of the right arity. The description of the free variables are taken from the grammar describing the closure and the description of the lambda-bound variables from the actual arguments. Termination Analysis. We use the result of the abstract transition semantics to determine which variables may be in situ increasing and which are guaranteed to be in situ decreasing: Given an endotransition t 2 atransp(fi; fi) we classify the variable xi;j as in situ increasing if 9h ; s; di 2 j(t); where s = I and j 2 d, and as in situ decreasing if 8h ; s; i 2 j(t) : s = ?; s = D(j); s = D(j f k); or s = E(j f k) for some f 2 Fnames; k 2 f1; : : : ; fv(f)g. It is obvious that xi;j is in situ decreasing if it is described by D(j). It is less obvious that the abstract value E(j f k) also guarantees this. Recall that E(j f k) means that value is weakly decreasing of the kth free variable in an l-closure taken from xi;j. Since closures are treated as data structures, E(j f k) describes a substructure of xi;j, which implies that xi;j is in situ decreasing. 8 Related Work, Conclusion, and Future WorkRelated Work. Jones, Gomard and Sestoft [11] present a termination analysisfor a owchart language, and Jones and Glenstrup [9] give e cient algorithmsfor implementing a termination analysis for a tail-recursive rst-order language.Both analyses use techniques similar to ours to reason about increasing and de-creasing variables. However, where we classify variables that may be unboundedas dynamic until no changes occur, they start by a division of dubious anddynamic variables, and classify dubious variables as static when they can beguaranteed to be bounded, and in the end classify the remaining dubious vari-ables as dynamic. Loosely, one can say that they approach the xpoint from thebottom, where we approach it from the top. It is unclear whether we end upwith the same xpoint.Conclusion. We have extended the rst-order analysis of Holst [10] to the higherorder case, thereby taking an step towards fully automatic partial evaluation ofhigher-order functional languages. Our analysis is strong enough to handle valuesowing in and out of closures, however the analysis sometimes fail to recognizein situ decreasing parameters due to the inevitable aliasing, which is necessaryto obtain a nite description.The analysis has been developed hand in hand with our experimental imple-mentation of the analysis6. This has made it possible for us to focus on practicalusefulness, in the sense that the analysis should be strong enough to handle alarge class of interesting programs. The focus has not been on speed, elegance, oran extensive correctness proof. In our opinion this has been an essential choice.We had to go through four major revisions of the analysis before our implemen-tation was capable of handling a su ciently large class of interesting programsto be of interest in a real partial evaluator. Our experiments with the implemen-tation of the analysis on interpreters written in di erent styles indicates, thatthe analysis is precise enough. The current implementation is too slow to be ofuse on programs of realistic size, but in our opinion we are not up against anyinherent complexity problem; just a slow implementation.Future Work. The techniques presented in this paper rely heavily on the use ofnitely downwards closed domains in the subject program, and it is not clearhow they can be extended to domains, that do not have a natural well-foundedsize ordering.The extension to structured datatypes is straightforward, e.g., for pairs sim-ply add a label for each cons in the program and collect the size informationusing the same techniques as for closures.Before the analysis can be integrated into Similix e cient algorithms mustbe developed. We expect that the algorithms of Jones and Glenstrup can beextended to serve this purpose.6 Thanks to Mark P. Jones for providing Gofer, without which it would have beenimpossible to conduct quite as many experiments as we did. Acknowledgements. Our thanks to Neil D. Jones and Arne Glenstrup for muchneeded sparring and helpful comments.References1. The Similix system, version 5.1. 1995.2. Lars Ole Andersen. Binding-time analysis and the taming of C pointers. In DavidSchmidt, editor, Proc. of ACM Symposium on Partial Evaluation and Semantics-Based Program Manipulation, PEPM'93, pages 47{58, 1993.3. Lars Ole Andersen. Program Analysis and Specialization for the C ProgrammingLanguage. PhD thesis, DIKU, University of Copenhagen, May 1994. (DIKU report94/19).4. Peter Holst Andersen and Carsten Kehler Holst. Termination Analysis for O inePartial Evaluation of a Higher Order Functional Language. Technical Report,DIKU, University of Copenhagen, Denmark, 1996. To appear.5. Anders Bondorf and Jesper J rgensen. E cient analyses for realistic o -line par-tial evaluation: extended version. Technical Report 93/4, DIKU, University ofCopenhagen, Denmark, 1993.6. Charles Consel. A tour of Schism: a partial evaluation system for higher-orderapplicative languages. In David Schmidt, editor, ACM SIGPLAN Symposium onPartial Evaluation and Semantics Based Program Manipulation, pages 145{154,June 1993.7. Charles Consel and Olivier Danvy. Partial evaluation of pattern matching instrings. Information Processing Letters, 30:79{86, January 1989.8. B. A. Davey and H. A. Priestley. Introduction to Lattices and Order. CambridgeMathematical Textbooks, Cambridge University Press, 1990.9. Arne J. Glenstrup and Neil D. Jones. BTA algorithms to ensure termination ofo -line partial evaluation. In Andrei Ershov Second InternationalConference \Per-spectives of System Informatics", Lecture Notes in Computer Science, 1996. Up-coming.10. Carsten Kehler Holst. Finiteness analysis. In John Hughes, editor, Functional Pro-gramming Languages and Computer Architectures, pages 473{495, ACM, Springer-Verlag, Cambridge, Massachusetts, USA, August 1991.11. Neil D. Jones, Carsten Gomard, and Peter Sestoft. Partial Evaluation and Auto-matic Program Generation. C.A.R. Hoare, Series Editor, Prentice Hall Interna-tional, International Series in Computer Science, June 1993. ISBN number 0-13-020249-5 (pbk).12. Neil D. Jones and Steven S. Muchnick. Flow analysis and optimization of Lisp-like structures. In Steven S. Muchnick and Neil D. Jones, editors, Program FlowAnalysis: Theory and Applications, chapter 4, pages 102{131, Prentice-Hall, 1981.13. H.G. Rice. Classes of recursively enumerable sets and their decision problems.Transaction of the AMS, 89:25{59, 1953.14. Peter Sestoft. Replacing Function Parameters by Global Variables. Master's thesis,DIKU, University of Copenhagen, Denmark, October 1988. 107 pages.15. David N. Turner, Philip Wadler, and Christian Mossin. Once upon a type. In 7'thInternational Conference on Functional Programming and Computer Architecture,pages 1{11, ACM Press, La Jolla, California, June 1995.This article was processed using theLATEX macro package with LLNCS style

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

The Generation of a Higher-Order Online Partial Evaluator

We address the problem of generating an online partial evaluator for a higher-order, functional language from an appropriate interpreter using a state-of-the-art ooine partial evaluator. To ensure termination of the generated online spe-cializer the interpreter computes a self-embedding property on closure values and data structures. This guarantees termination whenever there is no static loop ...

متن کامل

A Generic Framework for Specialization ( Abridged

We present a generic framework for specifying and implementing ooine partial evaluators. The framework provides the infrastructure for specializing higher-order programs with computational effects speciied through a monad. It performs sound specialization for all monadic instances and is evaluation-order independent. It subsumes most previously published partial evaluators for higher-order func...

متن کامل

Two Flavors of Ooine Partial Evaluation

Type-directed partial evaluation is a new approach to program specialization for functional programming languages. Its merits with respect to the traditional ooine partial evaluation approach have not yet been fully explored. We present a comparison of type-directed partial evaluation with standard ooine partial evaluation in both a qualitative and quantitative way. For the latter we use implem...

متن کامل

Termination Analysis for Offline Partial Evaluation of a Higher Order Functional Language

One of the remaining problems on the path towards fully automatic partial evaluation is ensuring termination of the specialization phase. In [10] we gave a termination analysis which could be applied to partial evaluation of first-order strict languages, using a new result about inductive arguments (loosely: if whenever something grows, something gets smaller then the program will only enter fi...

متن کامل

Termination Analysis for O ine Partial Evaluation of a Higher Order Functional Language

One of the remaining problems on the path towards fully automatic partial evaluation is ensuring termination of the specialization phase. In [Holst, 1991] we gave a termination analysis which could be applied to partial evaluation of rst-order strict languages, using a new result about inductive arguments (loosely: if whenever something grows, something gets smaller then the program will only e...

متن کامل

Implementing Memoization for Partial Evaluation

Memoization is a key ingredient in every partial evaluator. It enables folding by caching previously specialized functions. It is essential to make polyvariant specialization terminate. Its implementation is reasonably straightforward in a standard specializer that represents functions by closures. With the advent of handwritten program-generator generators (PGGs), implementing memoization gets...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 1996